package com.lovo.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.system.dto.SaleMesDto;
import com.lovo.system.mapper.SaleMesMapper;
import com.lovo.system.service.ISaleMesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SaleMesServiceImpl extends ServiceImpl<SaleMesMapper, SaleMesDto> implements ISaleMesService {

    @Autowired
    SaleMesMapper saleMesMapper;

    @Override
    public IPage<SaleMesDto> info(int curPage, int pageSize, String startTime, String endTime, String name) {
        QueryWrapper qw = new QueryWrapper();
        if (startTime!=null && !startTime.equals("")){
            qw.ge("sale_date",startTime);
        }
        if (endTime!=null && !endTime.equals("")){
            qw.le("sale_date",endTime);
        }
        if (name!=null && !name.equals("")){
            qw.like("customer_name",name);
        }
        return saleMesMapper.selectPage(new Page<>(curPage,pageSize),qw);
    }

    @Override
    public int insertSaleMes(SaleMesDto saleMesDto) {
        saleMesMapper.insert(saleMesDto);
        return saleMesDto.getSaleMesId();
    }

    @Override
    public List<String> selectCustomer() {
        return saleMesMapper.selectCustomer();
    }

    @Override
    public List<String> selectEmail(List<String> names) {
        return saleMesMapper.selectEmail(names);
    }

}
